<?php
class Rootmodel extends CI_Model{

public function __construct(){

        parent::__construct();
}

public function get_roots(){

$sql="select * from account";
  $query=$this->db->query($sql);
  if($query->num_rows()>0){
    $arr=$query->result_array();
    foreach ($arr as $key => $value) {
        foreach ($value as $key2 => $value2) {
        	if($key2=="depart"){
                          $sql="select * from depart where id='$value2'";

                        $query=$this->db->query($sql);
                        $row=$query->row();
                         $num=$query->num_rows();
                        if($num>0){
                                $arr[$key]['depart']=$row->name;
                        }else{
                        	
                            $arr[$key]['depart']="";
                        }

        	}elseif ($key2=="role_id") {
        		 $sql="select * from role where id='$value2'";
                        $query=$this->db->query($sql);
                        $row=$query->row();
                          $num=$query->num_rows();
                        if($num>0){
                                $arr[$key]['role_name']=$row->name;
                        }else{
                            $arr[$key]['role_name']="";
                        }

        	}
        }
    }
  }else{
    $arr=0;
  }
  return $arr;


}



public function get_departs(){
  $sql="select * from depart";
  $query=$this->db->query($sql);
  if($query->num_rows()>0){
    $arr=$query->result_array();
  }else{
    $arr=0;
  }
  return $arr;
}

public function get_roles(){
  $sql="select * from role";
  $query=$this->db->query($sql);
  if($query->num_rows()>0){
    $arr=$query->result_array();
  }else{
    $arr=0;
  }
  return $arr;
}


}


?>
